<?php
namespace Summer\Hjd\Models;

use \Backend\Models\ExportModel;
use Input;
use Config;

class WdRecordExport extends ExportModel {
    protected $fillable = [
        'start_date',
        'end_date',
    ];
    public function exportData($columns, $sessionKey = null)
    {
        if(Input::has('ExportOptions')){
            $filter=Input::get('ExportOptions');
            $start_date=$filter['start_date'];
            $end_date=$filter['end_date'];
        }
        $query=WdRecordModel::select();
        if($start_date){
            $query->where('created_at','>',$start_date);
        }
        if($end_date){
            $query->where('created_at','<',$end_date);
        }
        $records = $query->get();
        $records->each(function($record) use ($columns) {
            $record->target_username=$record->target->username??'暂无';
            $record->target_userphone=$record->target->userphone??'暂无';
            $record->currency_title=$record->currency->title;
            $record->status_title=Config::get('summer.hjd::wd_status.'.$record->status);
            $record->pay_type_title=Config::get('summer.hjd::wd_pay_type.'.$record->pay_type);

            if($record->pay_type==1){
                $bank_name=$record->target->bank_name??'暂无';
                $bank_number=$record->target->bank_number??'暂无';
                $bank_address=$record->target->bank_address??'暂无';
                $record->shoukuan_info='开户银行:'.$bank_name.'|银行卡号:'.$bank_number.'|开户行:'.$bank_address;
            }elseif($record->pay_type==2){
                $record->shoukuan_info='支付宝:'.$record->target->alipay_number;
            }elseif($record->pay_type==3){
                $record->shoukuan_info='微信:'.$record->target->wechat_number;
            }
            $record->addVisible($columns);
        });
        return $records->toArray();
    }
}
